    var type    = null;
    var offset  = 0;
    var count   = 15;
    var updates = null
    var liID    = null;

    $(document).ready(function(){ 
        initParam();
        setStyle("update");
        
/*        var swipelen = document.body.clientWidth/2;
        $.event.special.swipe.horizontalDistanceThreshold = swipelen;*/
        
        var name = "";
        switch(type){
            case "anime":
                name = "Аниме";
                break;
            
            case "manga":
                name = "Манга";
                break;
                
            case "rulate":
                name = "Rulate Project";
                break;
                
            case "ranobe":
                name = "Ранобэ";
                break;    
        }
        document.getElementById("p_head").innerHTML = name;
        
        if ( offset == "0" ){
            $("#a_head_l").hide();
        }else{
            $("#a_head_l").show();
        }
             
        $.mobile.loading('show');
        var http = "http://anibox.me/api.php?task=updates&type="+type+"&offset="+offset+"&count="+count;
        $.getJSON(http, parseJson);
    });    
    
    function parseJson(data){  
        if (data.length == 0){
            offset = parseInt(offset) - parseInt(count);
            window.localStorage.setItem("upOffset", offset);
            $('#a_head_r').hide();
            var http = "http://anibox.me/api.php?task=updates&type="+type+"&offset="+offset+"&count="+count;
            $.getJSON(http, parseJson);
            return;
        }
        
        updates = data;
        for (var i in data) {
            $('#dynamic_list_1').append(
                '<li id="' + data[i].id + '" onClick="liOnClick(this.id);">' +
                
                '<p>'+  data[i].pubdate+' МСК</p>'+
                '<div class="div_style_update" style="font-weight:bold;">'+
                 data[i].title +
                 '</div>'+
                '</li>\n'
            );
        }
        $('#dynamic_list_1').listview('refresh');
        $.mobile.loading('hide');
    }
    
    function initParam(){
        var befoPage = window.localStorage.getItem("befoPage");
        type = getParam("type");
        if (befoPage == "updates"){
            offset = 0
            window.localStorage.setItem("upOffset", offset);
        }else{
            offset = window.localStorage.getItem("upOffset");
        }
        
        count = getListCount();
        
    }
    
    //click list
    function liOnClick(id){
        liID = id;
        var db = getBD();
        db.transaction(saveChapterToDB, errorCB, successCB);
        goToPage("file:///android_asset/www/pages/records/chapter.html?id="+id);
    }
    
    //save chapter mark in bd
    function saveChapterToDB(tx){
        for(var i in updates){
            if( updates[i].id == liID){
                var url = updates[i].url;
                url = url.split("manga\/");              
                url = url[1].split("\/"+liID);
                tx.executeSql('CREATE TABLE IF NOT EXISTS chapters (_id INTEGER PRIMARY KEY, id_name)');
                tx.executeSql('INSERT INTO chapters (_id, id_name) VALUES ('+liID+','+url[0]+')');
            }
        }
    }
        
    //swipe(carusel)
/*    $(function(){
        // Bind the swipeHandler callback function to the swipe event on div.box
        $( "#options" ).on( "swiperight", swipeRight );
        $( "#options" ).on( "swipeleft", swipeLeft );
       
        // Callback function references the event target and adds the 'swipe' class to it
        function swipeRight( event ){
            updateBefo();
        }
        
        function swipeLeft( event ){
          updateNext();
        }
        
      });*/    
    
    //click in head befo
    function updateBefo(){
        var int = parseInt(offset) - parseInt(count);
        if (int == 0)
            $("#a_head_l").hide();
        if(int < 0){
            $("#a_head_l").hide();
            return "";
        }
        else{
            $('#a_head_r').show();
            $('#dynamic_list_1').empty();
            offset   = int;
            var http = "http://anibox.me/api.php?task=updates&type="+type+"&offset="+offset+"&count="+count;
            $.mobile.loading('show');
            $.getJSON(http, parseJson);
            window.scrollTo(0, 0);
            window.localStorage.setItem("upOffset", offset);
        } 
    }
    
    //click in head next
    function updateNext(){
        $("#a_head_l").show();
        $('#dynamic_list_1').empty();
        offset = parseInt(offset) + parseInt(count);
        var http = "http://anibox.me/api.php?task=updates&type="+type+"&offset="+offset+"&count="+count;
        $.mobile.loading('show');
        $.getJSON(http, parseJson); 
        window.scrollTo(0, 0);
        window.localStorage.setItem("upOffset", offset);
    }